<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>点击事件</title>
</head>

<body>
    <h1>点击p标签，切换颜色</h1>
    <hr />
</body>
<div id="demoReact"></div>
<script src="../../node_modules/babel-standalone/babel.min.js"></script>
<script src="../../node_modules/react/umd/react.development.js"></script>
<script src="../../node_modules/react-dom/umd/react-dom.development.js"></script>
<script type="text/babel">

    let arr = [1,2,3,4,5,6,7];

    let selectIndex = -1;

    function fun() {
        return (
            arr.map((v,i) => <p key={v} style={{color: i == selectIndex ? 'red' : 'blue'}} onClick={() => {selectIndex = i;render()}}>新闻{v}</p>)
        )
    }

    let root = ReactDOM.createRoot(document.getElementById("demoReact"));

    function render() {
        root.render(fun());
    }

    render();
</script>

</html>